package part3.c13_active_object;

import java.util.LinkedList;

/**
 * Created by lie on 2018/3/22.
 *
 */
public class ActiveObjectEngine {

    private LinkedList<Command> commandList = new LinkedList<Command>();

    public void addCommand(Command command){
        commandList.add(command);
    }

    /**
     * 引擎会确保所有的command都得到执行
     * 并确保是在command.execute()之后，再进行下一个
     * @throws Exception
     */
    public void run() throws Exception {

        while (! commandList.isEmpty()) {
            Command command = commandList.getFirst();
            commandList.removeFirst();
            command.execute();
        }

    }
}
